#include <iostream>
using namespace std;
int n,k;
int f[6005];
int num1[5005],num2[5005];
void cf(int a,int b,int c){
	int yx=c,xy=1;
	while(xy<yx){
		num1[++num1[0]]=xy*a;
		num2[++num2[0]]=xy*b;
		yx-=xy;
		xy*=2;
	}
	num1[++num1[0]]=yx*a;
	num2[++num2[0]]=yx*b;
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;++i){
		int a,b,c;
		cin>>a>>b>>c;
		cf(a,b,c);
	}
	for(int i=1;i<=num1[0];++i)
        for(int j=k;j>=num1[i];--j)
            f[j]=max(f[j],f[j-num1[i]]+num2[i]);
    cout<<f[k]<<endl;		
	return 0;
}
